class Solution:
    def isHappy(self, n: int) -> bool:
        his = set()
        while n not in his:
            if n == 1:
                return True
            his.add(n)
            n = sum([int(x) * int(x) for x in list(str(n))])
        return False


if __name__ == '__main__':
    so = Solution()
    s = 19
    r = so.isHappy(s)
    print(r)
